package com.angus.api.front.factory;

import com.angus.api.front.RemoteFrontUserService;
import com.angus.api.front.domain.FrontSendCode;
import com.angus.api.front.domain.FrontUser;
import com.angus.api.front.model.FrontLoginUser;
import com.angus.api.front.model.FrontUserStatistics;
import com.angus.common.core.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteFrontUserFallbackFactory implements FallbackFactory<RemoteFrontUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteFrontUserFallbackFactory.class);

    @Override
    public RemoteFrontUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteFrontUserService() {
            @Override
            public R<FrontLoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(FrontUser frontUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> recordUserLogin(FrontUser frontUser, String source)
            {
                return R.fail("记录用户登录信息失败:" + throwable.getMessage());
            }

            @Override
            public R<FrontLoginUser> selectUserByPhoneNum(String device, String source) {
                return R.fail("根据手机号查询用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<FrontLoginUser> selectUserByDevice(String device, Integer type, String source) {
                return R.fail("根据设备查询用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<FrontSendCode> queryLastSendCode(String device, Integer sceneCode, String dateTime, String source) {
                return R.fail("根据设备查询验证码信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> saveSendCode(FrontSendCode newSendCode, String source) {
                return R.fail("发送设备验证码失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> updateSendCode(FrontSendCode newSendCode, String source) {
                return R.fail("更新设备验证码失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> passwordRest(FrontUser frontUser, String source) {
                return R.fail("重置密码失败:" + throwable.getMessage());
            }

            @Override
            public R<FrontLoginUser> findUserByEmail(String email, String source) {
                return R.fail("通过邮箱查询用户失败" + throwable.getMessage());
            }

            @Override
            public R<FrontUserStatistics> getUserInfoCount(String source) {
                return R.fail("通过邮箱查询用户失败" + throwable.getMessage());
            }
        };
    }
}
